<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>构造一个异常（Exception）</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.errorexception.html">« ErrorException</a></li>
      <li style="float: right;"><a href="errorexception.getseverity.html">ErrorException::getSeverity »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.errorexception.html">ErrorException</a></li>
    <li>构造一个异常（Exception）</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="errorexception.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ErrorException::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ErrorException::__construct</span> &mdash; <span class="dc-title">构造一个异常（Exception）</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-errorexception.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ErrorException::__construct</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$code</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$severity</code><span class="initializer"> = <strong><code>E_ERROR</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$filename</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$line</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type"><a href="class.throwable.html" class="type Throwable">Throwable</a></span><span class="type"></span></span> <code class="parameter">$previous</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>)</div>

  <p class="para rdfs-comment">
   构造一个异常（Exception）。
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-errorexception.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">message</code></dt>

     <dd>

      <p class="para">
       抛出的异常消息内容。 
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">code</code></dt>

     <dd>

      <p class="para">
       异常代码。 
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">severity</code></dt>

     <dd>

      <p class="para">
       异常的严重级别。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        severity 可以是任意 <span class="type">int</span> 值，即<a href="errorfunc.constants.html" class="link">错误常量</a>里面的值。
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       抛出异常所在的文件名。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">line</code></dt>

     <dd>

      <p class="para">
       抛出异常所在的行号。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">previous</code></dt>

     <dd>

      <p class="para">
       异常链中的前一个异常。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-errorexception.construct-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       现在 <code class="parameter">filename</code> 和 <code class="parameter">line</code> 可以为空。
       之前，它们的默认值分别是 <strong><code>__FILE__</code></strong> 和
       <strong><code>__LINE__</code></strong> 。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

</div></div></div></body></html>